package com.snailthink.controller;

import com.snailthink.pojo.OrmCustomerVO;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
public class AjaxController {

    @RequestMapping("/test")
    public String test() {
        return "test";
    }


    @RequestMapping("/a1")
    public String a1(String name, HttpServletResponse response) throws IOException {

        System.out.println("a1"+name);
        if ("test".equals(name)){
            response.getWriter().print("true");
        }else {
            response.getWriter().print("false");
        }
        return name;
    }

    /**
     * 获取list数据
     * @return
     */
    @RequestMapping("/getList")
    public List<OrmCustomerVO> getList() {
        List<OrmCustomerVO> list = new ArrayList<OrmCustomerVO>();
        OrmCustomerVO ormCustomerVO1=new OrmCustomerVO();
        ormCustomerVO1.setCustomerNo("A123");
        ormCustomerVO1.setCustomerName("ABC");
        list.add(ormCustomerVO1);
        return list;
    }

    @RequestMapping("/a3")
    public String ajax3(String name,String pwd){
        String msg = "";
        //模拟数据库中存在数据
        if (name!=null){
            if ("admin".equals(name)){
                msg = "OK";
            }else {
                msg = "用户名输入错误";
            }
        }
        if (pwd!=null){
            if ("123456".equals(pwd)){
                msg = "OK";
            }else {
                msg = "密码输入有误";
            }
        }
        //由于@RestController注解，将msg转成json格式返回
        return msg;
    }

}
